﻿<UserControl x:Class="Administratation.Views.CountriesAndTowns"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:viewModels="clr-namespace:Administratation.ViewModels"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>

        <Grid Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <GroupBox Header="Manage Countries" Grid.Row="0" Margin="0,10,0,0">
                <Grid Grid.Row="0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <ListView ItemsSource="{Binding Countries}" DisplayMemberPath="Name" Width="150" Height="228"
                  IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Left" VerticalAlignment="Top">
                    </ListView>
                    <StackPanel Grid.Column="1" Margin="10,0,0,0">
                        <Expander IsExpanded="False" Header="Add New Country" Width="150">
                            <StackPanel>
                                <TextBlock Text="Country Name" />
                                <TextBox x:Name="textBoxAddCountryName" />
                                <Button x:Name="buttonAddCountry" Content="Add Country" Margin="0,5,0,5"
                                CommandParameter="{Binding ElementName=textBoxAddCountryName, Path=Text}"
                                Command="{Binding AddCountry}"/>
                            </StackPanel>
                        </Expander>

                        <GroupBox Header="Edit Country" Margin="0,10,0,0">
                            <StackPanel>
                                <StackPanel DataContext="{Binding Path=SelectedCountry}">
                                    <TextBlock Text="Country Name" />
                                    <TextBox x:Name="textBoxEditCountryName" >
                                        <TextBox.Text>
                                            <Binding Path="Name" UpdateSourceTrigger="PropertyChanged">

                                            </Binding>
                                        </TextBox.Text>
                                    </TextBox>

                                </StackPanel>
                                <Button x:Name="buttonEditCountry" Content="Save Country" Margin="0,5,0,5"
                            CommandParameter="{Binding SelectedCountry}"
                            Command="{Binding SaveCountry}"/>
                            </StackPanel>
                        </GroupBox>
                        <Button x:Name="buttonDeleteCountry" Content="Delete Country" Margin="0,5,0,5"
                            CommandParameter="{Binding SelectedCountry}"
                            Command="{Binding DeleteCountry}"/>
                    </StackPanel>
                </Grid>
            </GroupBox>
            
            <GroupBox Header="Manage Towns" Grid.Row="1" Margin="0,10,0,0">
                <Grid >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <ListView ItemsSource="{Binding Towns}" DisplayMemberPath="Name" Width="150" Height="228"
                              IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Left" VerticalAlignment="Top">
                    </ListView>
                    <StackPanel Grid.Column="1" Margin="10,0,0,0">
                        <Expander IsExpanded="False" Header="Add New Country" Width="150">
                            <StackPanel>
                                <TextBlock Text="Country Name" />
                                <TextBox x:Name="textBoxAddTownName" />
                                <Button x:Name="buttonAddTown" Content="Add Town" Margin="0,5,0,5"
                                CommandParameter="{Binding ElementName=textBoxAddTownName, Path=Text}"
                                Command="{Binding AddTown}"/>
                            </StackPanel>
                        </Expander>

                        <GroupBox Header="Edit Town" Margin="0,10,0,0">
                            <StackPanel>
                                <StackPanel DataContext="{Binding Path=SelectedTown}">
                                    <TextBlock Text="Town Name" />
                                    <TextBox x:Name="textBoxEditTownName" >
                                        <TextBox.Text>
                                            <Binding Path="Name" UpdateSourceTrigger="PropertyChanged">

                                            </Binding>
                                        </TextBox.Text>
                                    </TextBox>

                                </StackPanel>
                                <Button x:Name="buttonEditTown" Content="Save Town" Margin="0,5,0,5"
                            CommandParameter="{Binding SelectedTown}"
                            Command="{Binding SaveTown}"/>
                            </StackPanel>
                        </GroupBox>
                        <Button x:Name="buttonDeletTown" Content="Delete Town" Margin="0,5,0,5"
                            CommandParameter="{Binding SelectedTown}"
                            Command="{Binding DeleteTown}"/>
                    </StackPanel>
                </Grid>
            </GroupBox>
        </Grid>
        <Grid Name="GridInformation" Grid.Row="1">
            <TextBlock Text="{Binding OperationResult}"/>
        </Grid>
    </Grid>
</UserControl>
